{include file="public/nheader" /}
<style type="text/css">
    #lay-tableList {
        height: auto;
    }

    .layui-table-view .layui-table[lay-size=lg] .layui-table-cell {
        height: auto;
    }
</style>
<div class="layui-fluid">
    <div class="layui-card">
        <!-- // 默认操作按钮 -->
        <div class="layui-card-header layadmin-card-header-auto ">
            <div class="layui-form">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <input name="title" class="layui-input" type="text" placeholder="用户名|身份证|手机号" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="status">
                                <option value="">状态</option>
                                <option value="1" {if !empty(input('get.status')) &&
                                    input('get.status')==1}selected{/if}>在线</option>
                                <option value="2" {if !empty(input('get.status')) &&
                                    input('get.status')==2}selected{/if}>忙碌</option>
                                <option value="3" {if !empty(input('get.status')) &&
                                    input('get.status')==3}selected{/if}>下线</option>
                            </select>
                        </div>
                    </div>
                    <!-- <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="istdz">
                                <option value="">是否团队长</option>
                                <option value="1" {if !empty(input('get.istdz')) && input('get.istdz')==1}selected{/if}>
                                    否</option>
                                <option value="2" {if !empty(input('get.istdz')) && input('get.istdz')==2}selected{/if}>
                                    是</option>
                            </select>
                        </div>
                    </div> -->
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="province" lay-filter="province">
                                <option value="">请选择搜索省份</option>
                                {foreach $province as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.province')) &&
                                    input('get.province')==$v.area_code}selected{/if}>{$v.name}</option>
                                {/foreach}
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="city" lay-filter="city">
                                <option value="">请选择搜索城市</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="area" lay-filter="area">
                                <option value="">请选择搜索区域</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline ">
                            <select name="street" lay-filter="street">
                                <option value="">请选择搜索街道</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- // 默认搜索 -->
                        <button class="layui-btn icon-btn" lay-filter="formSearch" lay-submit>搜索</button>
                        <!-- // 删除所有 -->
                        <button class="layui-btn icon-btn layui-btn-danger" lay-batch="lay-tableList"
                            data-url="/agent/rider_del">批量删除
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <!-- // 创建数据实例 -->
        <table id="lay-tableList" lay-filter="lay-tableList"></table>
    </div>
</div>
<!-- // 列表工具栏 -->
<script type="text/html" id="tableBar">
    <a class="layui-table-text" lay-open data-title="编辑" data-area="60%,80%" data-url="/agent/rider_edit?id={{d.id}}" >编辑</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" lay-open data-title="管理街道" data-area="90%,90%" data-url="/agent/riderstreet?rider={{d.id}}" >管理申请</a>
    <br/>
    <a class="layui-table-text" data-url="/agent/rider_del?id={{d.id}}" lay-event="del">删除</a>
    <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" lay-open data-title="最近轨迹(非实时位置，由于小程序官方权限限制,位置信息仅在骑手访问、接取订单时更新，仅供参考)" data-area="90%,90%" data-url="/agent/riderlat?id={{d.id}}" >最近轨迹</a>
    <!-- <div class="layui-divider layui-divider-vertical"></div>
    <a class="layui-table-text" onclick="delAll('/agent/rider_status', '{{d.id}}')">{{d.pid  > 0 ? '修改':'设置'}}团队长</a> -->
</script>
{include file="public/nfooter"}
<script type="text/html" id="moneyBar">
    <a style="color:blue" class="layui-table-text" lay-open data-title="收益明细" data-area="60%,80%" data-url="/agent/rmoneylog?id={{d.id}}" >{{d.money}}</a>
    <a class="layui-table-text" data-title="操作收益" data-area="30%,40%" callback="edits" data-url="#adminforms" lay-event="edit">修改</a>
</script>
<script type="text/html" id="adminforms">
    <div class="layui-fluid layui-bg-white">
        <form class="layui-form layui-form-fixed" lay-filter="adminforms">
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>师傅ID:</label>
                    <div class="layui-input-block">
                        <input name="id" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><font color="red">* </font>师傅姓名:</label>
                        <div class="layui-input-block">
                            <input name="name" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                        </div>
                    </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>可用金额:</label>
                    <div class="layui-input-block">
                        <input name="money" style="border:none;display: inline-block;" class="layui-input" disabled onlyread/>
                    </div>
                </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>类型:</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="1" title="增加" checked>
                    <input type="radio" name="type" value="2" title="扣除">
                </div>
            </div>
            <div class="layui-form-item">
            <label class="layui-form-label"><font color="red">* </font>变更金额:</label>
                <div class="layui-input-block">
                    <input name="moneys" value=""  placeholder="增减金额" type="number" class="layui-input" lay-verify="required" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><font color="red">* </font>操作说明:</label>
                <div class="layui-input-block">
                    <textarea name="desc" placeholder="请输入内容" class="layui-textarea" lay-verify="required" >平台操作</textarea>
                </div>
            </div>
        <div class="layui-footer layui-form-item layui-center ">
            <button class="layui-btn" lay-filter="submitPage" lay-submit>提交</button>
            <button class="layui-btn layui-btn-primary" type="button" sa-event="closePageDialog" >取消</button>
        </div>
        </form>
    </div>
</script>
<script>
    function delAll(url, id) {
        var ids = id;
        layer.prompt({ title: '填写团队长师傅账号,并确保账号已设置为团队长' }, function (value, index, elem) {
            //捉到所有被选中的，发异步进行删除
            $.post(url, { id: ids, value: value },
                function (data) {
                    if (data.code == 200) {
                        layer.msg(data.msg, function () {
                            // 获得frame索引
                            location.reload();
                            layer.close();
                        });
                    } else {
                        layer.msg(data.msg, 'error');
                    }
                }, "json"
            ).error(function () {
                layer.msg('请求错误,请重试', 'error');
            });
        });
    }
    layui.use(['admin', 'layer', 'table', 'form'], function () {
        var admin = layui.admin;
        var layer = layui.layer;
        var table = layui.table;        // 表格
        var form = layui.form; admin.callback.edits = function (clickthis, colletction, config) {
            var tableThis = colletction.tableThis;
            // 监听权限提交
            form.on("submit(submitPage)", function (post) {
                // 获取用户id
                var pageThat = layui.$(this);
                pageThat.attr("disabled", true);
                // 开始POST提交数据
                post.field.id = tableThis.data.id;
                var index = layer.load(1); //换了种风格           
                layui.$.post("{:url('agent/rmoney_edit')}", post.field, function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg);
                        // 关闭当前窗口
                        table.reload('lay-tableList');
                        layer.close(colletction.index);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                    else {
                        layer.error(res.msg);
                        layer.close(index);
                        pageThat.attr("disabled", false);
                    }
                }, 'json').error(function () {
                    layer.close(index);
                    pageThat.attr("disabled", false);
                    layer.msg('请求错误,请重试', 'error');
                });
                return false;
            })
        }
        /*
         * 初始化表格
        */
        var isTable = table.render({
            elem: "#lay-tableList",
            where: {
                agentid: "{:input('agentid/d',0)}"
            }
            , url: "{:url()}"
            , page: true
            , size: 'lg'
            , even: true
            , cols: [[
                { type: 'checkbox', width: 60 },
                { field: 'id', align: 'center', sort: true, width: 80, title: 'ID' },
                {
                    field: 'bh', align: 'center', sort: true, width: 120, title: '服务工号', templet: function (d) {
                        if (d.bh) {
                            return d.bh;
                        } else {
                            return '无';

                        }
                    }
                },
                // {
                //     field: 'istdz', align: 'center', width: 80, templet: function (d) {
                //         var text = '';
                //         if (d.istdz == 2) {
                //             text = '<span class="layui-badge layui-bg-blue">是</span>';
                //         } else {
                //             text = '<span class="layui-badge layui-bg-orange">否</span>';
                //         }
                //         return text;

                //     }, title: '团队长'
                // },
                {
                    field: 'status', align: 'center', width: 100, templet: function (d) {
                        var text = '';
                        if (d.status == 1) {
                            text = '<span class="layui-badge layui-bg-blue">在线</span>';
                        }
                        if (d.status == 2) {
                            text = '<span class="layui-badge layui-bg-orange">忙碌</span>';
                        }
                        if (d.status == 3) {
                            text = '<span class="layui-badge layui-bg-green">下线</span>';
                        }
                        return text;

                    }, title: '类型'
                },
                {
                    field: 'name', align: 'center', width: 200, title: '名称/身份证/账号', templet: function (d) {
                        return d.name + '<br/>' + d.cards + '<br/>' + d.mobile;
                    }
                },
                {
                    field: 'money', align: 'center', width: 150, toolbar: '#moneyBar', title: '收益明细'
                },
                // {
                //     field: 'name', align: 'center', width: 200, title: '团队长信息', templet: function (d) {
                //         if (d.tdzname) {
                //             return d.tdzname + '<br/>' + d.tdzcards + '<br/>' + d.tdzmobile;
                //         }
                //         return '无';
                //     }
                // },
                {
                    field: 'income', align: 'center', width: 150, templet: function (d) {
                        var text1 = '<a style="color:blue" class="layui-table-text" lay-open data-title="完成" data-area="90%,90%" data-url="/orders/index?triderid=' + d.id + '&status=4" >' + d.incomecount + '单/' + d.income + '元</a><br/>';
                        var text2 = '<a style="color:blue" class="layui-table-text" lay-open data-title="完成" data-area="90%,90%" data-url="/orders/index?riderid=' + d.id + '&status=4" >' + d.count + '单/' + d.total + '元</a>';
                        return text1 + text2;
                    }, title: '推荐订单/完成订单'
                },
                // {
                //     field: 'positive', align: 'center', width: 200, templet: function (d) {
                //         var text = d.positive ? '<div><img style="width:50px" src="' + d.positive + '"lay-image-click=""></div>' : '<div></div>';
                //         var text2 = d.negative ? '<div><img style="width:50px" src="' + d.negative + '"lay-image-click=""></div>' : '<div></div>';
                //         return text + text2;
                //     }, title: '身份证图片'
                // },
                { field: 'created', width: 200, align: 'center', title: '注册时间' },
                { align: 'center', toolbar: '#tableBar', width: 250, title: '操作' },
            ]]
        })
    })
</script>
</body>